var utils = require('../../../utils/util.js')
var c = require('../../../utils/config.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loglist: [
    //   {
    //   curl_ym: "",
    //   reducenum:0,
    //   addnum:0,
    //   list:[],
    // }
    ],
    page: 1,
    img_url: c.img_url,
    ym: "",
    select:1
  },
  onLoad: function (options) {
    var that = this;
    var token = wx.getStorageSync("userinfo").wap_token;

    var data = {
      url: "/zfshop/uservipnumslog/lists",
      type: that.data.select,
      ym: that.data.ym,
      token: token,
    };
    utils.request(data).then(function (res) {
      if (res.code == 0) {
        let data = res.data;
        let reducenum = 0;
        let addnum = 0;
        for (let i = 0; i < data.list.length;i++){
          if (data.list[i].type==0){
            addnum += data.list[i].nums;
          }else if (data.list[i].type == 1) {
            reducenum += data.list[i].nums;
          }
        }
        if (data.list.length > 0){
          let loglist = {};
          loglist.list=data.list;
          loglist.curl_ym = data.curl_ym;
          loglist.reducenum = reducenum;
          loglist.addnum = addnum;
          that.setData({
            loglist: that.data.loglist.concat(loglist),
            ym: data.ym
          });
        }
      } else {

      }
    });
  },
  /**
     * 页面上拉触底事件的处理函数
     */
  onReachBottom: function () {
    this.onLoad();
  },
  selecttab:function(e){
    this.setData({
      loglist: [],
      ym: '',
      curl_ym:'',
      reducenum: 0,
      addnum: 0,
      select: e.currentTarget.dataset.select,
    });
    this.onLoad();
  },
})

